package com.yubest.rabbitmq.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RoutingDirectConsumer {

    @RabbitListener(
            bindings = {@QueueBinding(
                    exchange = @Exchange(name = "test.routing.direct.exchange", type = ExchangeTypes.DIRECT),
                    key = {"test.routing.direct.key1", "test.routing.direct.key2"},
                    value = @Queue("test.routing.direct.queue1"))})
    public void consumer1(String msg) {
        log.info("类型【routing direct】，交换机【test.routing.direct.exchange】，路由key【test.routing.direct.key1、test.routing.direct.key2】，队列【test.routing.direct.queue1】，收到的消息【{}】", msg);
    }

    @RabbitListener(
            bindings = {@QueueBinding(
                    exchange = @Exchange(name = "test.routing.direct.exchange", type = ExchangeTypes.DIRECT),
                    key = {"test.routing.direct.key3", "test.routing.direct.key4"},
                    value = @Queue("test.routing.direct.queue2"))})
    public void consumer2(String msg) {
        log.info("类型【routing direct】，交换机【test.routing.direct.exchange】，路由key【test.routing.direct.key3、test.routing.direct.key4】，队列【test.routing.direct.queue2】，收到的消息【{}】", msg);
    }

}
